package cn.ekuma.epos.crm.link;

import cn.ekuma.epos.analysis.front.customerAction.AnalysisModelManager;
import cn.ekuma.epos.datalogic.I_DataLogicERP;

import com.openbravo.bean.BusinessPartner;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.gui.MessageInf;
import com.openbravo.data.loader.query.QBFCompareEnum;

import com.openbravo.pos.base.AppLocal;
import com.openbravo.pos.panels.event.TimeCycleChangedEvent;

public class JCustomerActionLinkPanel extends AbstractCustomerLinkTimeCycleTreeTablePanel{

	Object[] afilter;
	AnalysisModelManager manager;
	
	public JCustomerActionLinkPanel(I_DataLogicERP dlSales) {
		super(dlSales);
		manager=new AnalysisModelManager(dlSales);
		jXTable1.setTreeTableModel(manager.getTreeTableModel());
	}

	@Override
	public void timeCycleChanged(TimeCycleChangedEvent e) {
		if(afilter==null)
			afilter=(Object[]) createValue();
		  afilter[0] = (e.getStartDate()== null)? QBFCompareEnum.COMP_NONE: QBFCompareEnum.COMP_GREATEROREQUALS;
	      afilter[1] = e.getStartDate();
	      afilter[2] = ( e.getEndDate() == null) ? QBFCompareEnum.COMP_NONE: QBFCompareEnum.COMP_LESS;
	      afilter[3] = e.getEndDate();
	      query();
	}
	

	public Object createValue() {
		Object[] afilter = new Object[10];
        // Date range
      Object startdate = null;
      Object enddate = null;

      afilter[0] = (startdate == null) ? QBFCompareEnum.COMP_NONE : QBFCompareEnum.COMP_GREATEROREQUALS;
      afilter[1] = startdate;
      afilter[2] = (enddate == null) ? QBFCompareEnum.COMP_NONE : QBFCompareEnum.COMP_LESS;
      afilter[3] = enddate;

      //Customer
      
          afilter[4] = QBFCompareEnum.COMP_NONE;
          afilter[5] = null;
      
      
      //Location
      afilter[6] = QBFCompareEnum.COMP_NONE;
      afilter[7] = null;
      
          
     //Operation Cateory
      afilter[8]=QBFCompareEnum.COMP_NONE;
      afilter[9]=null;
    
          
     return afilter;
	}
	
	
	public void query(){
		if(afilter==null||afilter[5] == null)
			return;
		try {
			manager.query(afilter);
		} catch (BasicException e) {
			new MessageInf(e).show(this);
		}
	}
	
	public static String getTabName(){
		return AppLocal.getIntString("Menu.CustomerActionAnalysisPanel");
	}

	@Override
	public void baseBeanChanged(BusinessPartner o) {
		if(afilter==null)
			afilter=(Object[]) createValue();
		 afilter[4] = QBFCompareEnum.COMP_IN;
         afilter[5] = new String[]{o.getId()};
         query();
		
	}

	@Override
	public void resertTableModel() {
		
	}

}

